package rabbit.ack;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.MessageProperties;
import rabbit.util.RabbitMqUtils;

import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

/**
 * Created with IntelliJ IDEA.
 * ClassName: Task2
 * Package: rabbit.ack
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-10-25
 * Time: 17:05
 */

public class Task2 {

    //消息在手动应答时是不丢失 放回队列中重新消费

    //队列

    public static final String TACK_QUEUE_NAME = "ack_queue";

    public static void main(String[] args) throws IOException, TimeoutException {
        Channel chanel = RabbitMqUtils.getChanel();
        //队列名称 是否持久化 是否共享 消费之后是否自动删除 其他参数
        chanel.queueDeclare(TACK_QUEUE_NAME,false,false,false,null);
        //从控制台中输入信息

        //在生产段 开启发布确认
        chanel.confirmSelect();

        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
            String next = scanner.next();

            //信道发送消息
            //交换机，队列名称 其他参数 消息
            //生成者发送消息持久化  MessageProperties.PERSISTENT_TEXT_PLAIN 持久化磁盘
            chanel.basicPublish("",TACK_QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN,next.getBytes());

            System.out.println("生产者发送消息: " + next);
        }
    }


}
